package com.alan.base.utils;

import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;

public class ViewUtils {

    public static void setViewClickEffect(@NonNull View view){
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        view.setAlpha(0.5f);
                        break;
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                    case MotionEvent.ACTION_OUTSIDE:
                        view.setAlpha(1.0f);
                        break;
                }
                return view.onTouchEvent(motionEvent);
            }
        });

    }

}
